/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.session;

import com.thienloc.omap.entity.report.ReconcileReport;
import java.util.List;
import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author GiangLT
 */
@Stateless
public class ReconcileReportFacade extends AbstractFacade<ReconcileReport> {

    @PersistenceContext(unitName = "omapPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ReconcileReportFacade() {
        super(ReconcileReport.class);
    }

    public List<ReconcileReport> getReconcileReport(String date, String sqlDateFormat) throws Exception {
        try {
            Query q = em.createNativeQuery("BEGIN get_reconcile_report(reconcile_date=>?, sql_date_format=>?); END;");
            q.setParameter(1, date);
            q.setParameter(2, sqlDateFormat);
            q.executeUpdate();
            //
            q = em.createNamedQuery("ReconcileReport.findAll", ReconcileReport.class);
            List<ReconcileReport> result = q.getResultList();
            return result;

        } catch (NoResultException ex) {
            return null;
        } catch (Exception ex) {
            LoggerFactory.getLogger(ReconcileReportFacade.class.getName()).error("", ex);
            throw ex;
        }
    }
}
